package com.zkrt.upms.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.zkrt.upms.entity.DeviceB;
import com.zkrt.upms.service.IDeviceBService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/device")
public class DeviceController {

    @Autowired
    private IDeviceBService deviceService;

    /**
     * 查询设备（分页）
     * @param sn
     * @param name
     * @param current
     * @param size
     * @return
     */
    @GetMapping("/page")
    public @ResponseBody R page(@RequestParam(required = false, value = "sn") String sn,
                                @RequestParam(required = false, value = "name") String name,
                                @RequestParam(required = false, value = "disabled") Boolean disabled,
                                @RequestParam(required = false, value = "current") Long current,
                                @RequestParam(required = false, value = "size") Long size) {
        return deviceService.page(sn, name, disabled, current, size);
    }

    /**
     * 配置设备
     * @param devices
     * @return
     */
    @PostMapping("/config")
    public @ResponseBody R config(@RequestBody(required = false) List<DeviceB> devices) {
        return deviceService.config(devices);
    }

    //查询所有设备
    @GetMapping("/getAll")
    public @ResponseBody R getAll() {
        return deviceService.getAll();
    }

    //查询所有设备属性
    @GetMapping("/getAllAttr")
    public @ResponseBody R getAllAttr() {
        return deviceService.getAllAttr();
    }

    /**
     * 删除设备
     * @param ids
     * @return
     */
    @DeleteMapping("/delete")
    public @ResponseBody R delete(@RequestBody(required = false) List<String> ids) {
        return deviceService.delete(ids);
    }


    //获取每日补录脚本
    @GetMapping("/getScript")
    public @ResponseBody String getScript(String day) {
        return deviceService.getScript(day);
    }

}
